{layout name="layout/header" /}
<link href="root/css/plugins/footable/footable.core.css" rel="stylesheet">
<link href="root/css/plugins/iCheck/custom.css" rel="stylesheet">
<link href="root/css/plugins/datetimepicker/bootstrap-datetimepicker.css" rel="stylesheet">

<link href="root/css/plugins/switchery/switchery.css" rel="stylesheet">
<script src="root/js/plugins/switchery/switchery.js"></script>
<div class="wrapper wrapper-content animated fadeInRight" id="app">
    <div class="row">
        <div class="col-sm-12">
            <div class="ibox float-e-margins">
                <div class="ibox-title">
                    <h5><a href="{:url('vote/index')}">活动列表</a>/<a href="{:url('vote_items/index',['vote_id'=>$vote['id']])}">{$vote.name}</a>/批量导入</h5>
                    <div class="ibox-tools">
                        <a type="button" class="btn btn-primary btn-sm" href="{:url('index',['vote_id'=>$vote.id])}">返回列表页</a>
                    </div>
                </div>
                <div class="ibox-content">
                    <form method="post" class="form-horizontal" id="form">
                        <div class="form-group">
                            <label class="col-sm-1 control-label">是否分类</label>
                            <div class="col-sm-10">
                                <div class="radio i-checks">
                                    <label><input type="radio" v-model="is_tag" value="1" name="is_tag"> <i></i>是</label>
                                    <label><input type="radio" v-model="is_tag" value="0" name="is_tag"> <i></i>否</label>
                                </div>
                            </div>
                        </div>
                        <div class="form-group" v-if="is_tag==1">
                            <label class="col-sm-1 control-label">分类标记</label>
                            <div class="col-sm-11">
                                <input type="text" class="form-control" v-model="tag_field" name="tag_field">
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-1 control-label">编号字段名</label>
                            <div class="col-sm-11">
                                <input type="text" class="form-control" v-model="id_field" name="id_field">
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-1 control-label">名称字段名</label>
                            <div class="col-sm-11">
                                <input type="text" class="form-control" v-model="name_field" name="name_field">
                            </div>
                        </div>
                        <!--图片上传-->
                        <div class="form-group">
                            <label class="col-sm-1 control-label">数据文件</label>
                            <div class="col-sm-10">
                                <button class="btn btn-success product_upload_img" type="button">
                                    <i class="fa fa-upload"></i>&nbsp;&nbsp;<span class="bold">上传</span>
                                </button>
                                <input class="vue_img" type="file" style="display: none;" data-field="img"/>
                            </div>
                            <div class="col-sm-11 col-sm-offset-1 ">
                                <div class="row" id="img">
                                    <div class="img_box col-xs-12 col-md-3" v-if="img!=''">
                                        <span>{{img}}</span>
                                        <a class="glyphicon glyphicon-trash" onclick="del_wx_img(this,'img');"></a>
                                    </div>
                                </div>
                            </div>
                        </div>
                        <!--图片上传-->
                        <div class="hr-line-dashed"></div>
                        <div class="form-group">
                            <div class="col-sm-4 col-sm-offset-2">
                                <a class="btn btn-primary" @click="submit" type="submit">保存内容</a>
                            </div>
                        </div>
                    </form>
                </div>
            </div>
        </div>
    </div>
</div>

<script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>
<!-- iCheck -->
<script src="root/js/plugins/iCheck/icheck.min.js"></script>
<!--layer-->
<script src="root/js/plugins/layer/layer.min.js"></script>
<script src="root/js/plugins/datetimepicker/bootstrap-datetimepicker.js"></script>
<script src="root/js/plugins/datetimepicker/bootstrap-datetimepicker.zh-CN.js"></script>
<script src="root/js/plugins/validate/jquery.validate.min.js"></script>
<script src="root/js/plugins/validate/messages_zh.min.js"></script>
<script>
    var voteId = "{$vote.id}";
    var url = "{:url('batch',['vote_id'=>$vote.id])}";
    data = {
        is_tag:0,
        tag_field:'',
        name_field:'',
        id_field:'',
        img:'',
    }
    new Vue({
        el:"#app",
        data:data,
        methods:{
            submit:function () {
                const _this = this;
                if(_this.is_tag==1 && !_this.tag_field){
                    layer.msg('分类标记不能为空')
                    return false
                }
                if(!_this.name_field){
                    layer.msg('名称字段不能为空')
                    return false
                }
                if(!_this.id_field){
                    layer.msg('id字段不能为空')
                    return false
                }
                if(!_this.img){
                    layer.msg('数据文件不能为空')
                    return false
                }
                layer.msg('加载中', {
                    icon: 16
                    ,shade: 0.1
                    ,time:false
                });
                $.post(url,data,function (res) {
                    layer.closeAll();
                    layer.msg(res.msg);
                    if(res.code==1){
                        setTimeout(function () {
                            window.location.href= "{:url('index',['vote_id'=>$vote.id])}"
                        },1500)
                    }
                },'json')
            }
        },
        mounted:function () {
            checks();
        }
    });
</script>

<script>
    $('input[name="is_tag"]').on('ifChecked', function(event){
        data.is_tag = $(this).val()
    });

</script>
